""" Some handy util functions """

def find_key(dic, val):
    #
    """return the key of dictionary dic given the value"""
    #
    return [k for k, v in dic.iteritems() if v == val][0]

def concatTupleListIndex(tuple_list, tuple_index):
    """
        Concats the values of each tuple at index tuple_index
        tuple_list can be a list of tuples or a single tuple
    """
    if (isinstance(tuple_list, list)):
        result = ""
        for tuple in tuple_list:
            result = result + " " + tuple[tuple_index]
        return result.strip()
    else:
        return tuple_list[tuple_index]